from django.db import models

# Create your models here.

# 会员管理模型
class Users(models.Model):
    # id 手机号 密码
    phone = models.CharField(max_length=11)
    password = models.CharField(max_length=80)
    face = models.CharField(max_length=100,default='/static/myadmin/assets/img/user.jpg')
    # 昵称 居住地址 性别 身份类型
    nikename = models.CharField(max_length=20,null=True)
    homeaddress = models.CharField(max_length=100,null=True)
    sex = models.CharField(max_length=1,null=True)
    usertype = models.CharField(max_length=1,null=True)
    registerdate = models.DateTimeField(auto_now_add=True)

# 图书分类模型
class booktype(models.Model):
    name = models.CharField(max_length=20)
    pid = models.IntegerField()
    path = models.CharField(max_length=50)

# 图书商品模型
class Books(models.Model):
    typeid = models.ManyToManyField(to='booktype')  #id
    title = models.CharField(max_length=50)  # 书名
    tuijian = models.CharField(max_length=255) # 推荐
    author = models.CharField(max_length=50) # 作者
    publisher = models.CharField(max_length=100) # 出版社
    pub_date = models.DateField() #出版时间
    price = models.FloatField() # 价格
    num = models.IntegerField() # 数量
    isbn = models.CharField(max_length=30) # 书号
    context = models.TextField() # 内容

# 图书封面图
class BookImgs(models.Model):
    bookid = models.ForeignKey('Books',on_delete=models.CASCADE,)
    img_url = models.ImageField(upload_to='static/uploads/')

# 购物车模型
class Cart(models.Model):
    # 用户id，商品id,数量，select
    uid = models.ForeignKey('Users',on_delete=models.CASCADE,)
    bid = models.ForeignKey('Books',on_delete=models.CASCADE,)
    num = models.IntegerField()
    # 是否选中
    select = models.IntegerField(default=0)